import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

///
/// 那时我们有梦
/// 关于文学
/// 关于爱情
/// 关于穿越世界的旅行
/// 如今我们深夜饮酒
/// 杯子碰到一起
/// 都是梦破碎的声音
///
class UnKeepLiveWidget extends StatefulWidget {
  const UnKeepLiveWidget({super.key});

  @override
  State<UnKeepLiveWidget> createState() => _UnKeepLiveWidgetState();
}

class _UnKeepLiveWidgetState extends State<UnKeepLiveWidget> {
  @override
  void initState() {
    super.initState();
    debugPrint("_UnKeepLiveWidgetState我被创建了哦");
  }

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        Padding(
          padding: EdgeInsets.symmetric(horizontal: 20).copyWith(top: 10),
          child: Text("我这个页面无法保存状态"),
        ),
        Expanded(
          child: ListView.separated(
            itemBuilder: (ctx, index) => TestItemWidget(
              index: index,
            ),
            separatorBuilder: (BuildContext context, int index) => Divider(),
            itemCount: 300,
          ),
        ),
      ],
    );
  }
}

class TestItemWidget extends StatefulWidget {
  final int index;

  const TestItemWidget({super.key, required this.index});

  @override
  State<TestItemWidget> createState() => _TestItemWidgetState();
}

class _TestItemWidgetState extends State<TestItemWidget> {
  @override
  void initState() {
    super.initState();
    debugPrint("我被创建了哦${widget.index}");
  }

  @override
  Widget build(BuildContext context) {
    return ListTile(
      title: Text("我是第${widget.index}个"),
    );
  }

  @override
  void dispose() {
    super.dispose();
    debugPrint("你看我离屏销毁了哦${widget.index}");
  }
}
